﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using iLangl.Model;

namespace iLangl.Tests.CustomerActions
{
	[TestClass]
	public class ProjectValidationTest : BaseTest
	{
		[TestMethod]
		public void ProjectValidation()
		{

			Project project = GetProject();

			ProjectRequestContext requestContext = new ProjectRequestContext();


			requestContext.SetContext(project);
			string serializedproject = requestContext.GetContext().ToString();

			ProjectResponseContext responsecontext = new ProjectResponseContext();
			responsecontext.SetContext(serializedproject);

			Project project2 = (Project)responsecontext.GetContext();
			requestContext.SetContext(project2); 
			string serializedproject2 = requestContext.GetContext().ToString();

			Assert.AreEqual(serializedproject, serializedproject2);
		}


		#region Helpers Methods
		protected Project GetProject()
		{
			Project project = new Project();
			project.Id = "FA8E4A8A-8655-4340-9A59-63597E1C4774";
			project.Name = "Test Project";
			project.Description = "This is a test project created for test purposes";
			project.Deadline = DateTime.Now.AddDays(5);

			project.Owner = new Contact();
			project.Owner.Id = "936AFC19-9F04-45DA-A2FC-91B2984E9149";
			project.Owner.FirstName = "Sergey";
			project.Owner.LastName = "Yuryev";
			project.Owner.Company = new Company();
			project.Owner.Company.Id = TestSettings.TestCompanyId;
			project.Owner.Company.Name = TestSettings.TestCompanyName;
			project.Owner.Email = "sergey.yuryev@gmail.com";
			

			project.TechnicalContact = project.Owner;
			project.WorkArea = new WorkArea();
			project.WorkArea.Id = TestSettings.TestWorkAreaId;
			project.WorkArea.Name = "IT Industry";

			project.Product = new Product();
			project.Product.Id = TestSettings.TestProductId;
			project.Product.Name = "Direct Translation";

			project.Status = ProjectStatuses.Configuration;

			ContentEntity originalContent = new ContentEntity();
			originalContent.Id = "489C330E-98AD-4910-8CBA-35E8FD834EB3";
			originalContent.Language = new Language();
			originalContent.Language.LanguageId = "1";
			originalContent.Language.LanguageName = "English";
			originalContent.Name = "Test Content";
			originalContent.Version = "1";
			originalContent.Content = @"<test> Hello World</test>";
			originalContent.Type = "XML";

			project.Contents = new ContentEntity[] { originalContent };

			Translation translation = new Translation();
			translation.Id = "661A1F47-24B7-4272-9C9E-C0D27933CD02";
			translation.Progress = 0;
			translation.Status = TranslationStatuses.Configuration;
			translation.LanguagePair = new LanguagePair();
			translation.LanguagePair.SourceLanguage = originalContent.Language;
			translation.LanguagePair.TargetLanguage = new Language();
			translation.LanguagePair.TargetLanguage.LanguageId = "2";
			translation.LanguagePair.TargetLanguage.LanguageName = "Russian";
			
			translation.SourceContent = originalContent;
			project.Translations = new Translation[] { translation };


			return project;
		}
		#endregion
	}
}
